//
//  ZGWJiBingFengXianJiuZhengViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/6/3.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "ZGWJiBingFengXianJiuZhengViewController.h"
#import "ZGWJiBingFengXianJiuZhengFirstTableViewCell.h"
#import "ZGWJiBingFengXianJiuZhengSecondTableViewCell.h"
#import "ZGWJiBingFengXianJiuZhengThirdTableViewCell.h"
#import "ZGWJiBingFengXianJiuZhengFourthTableViewCell.h"
#import "ZGWDieaseHistoryModel.h"
#import "ZGWShengHuoXiGuanModel.h"
#import "ZGWJiaZuShiModel.h"
#import "ZGWAgeModel.h"
#import "ZGWGenderModel.h"
#import "ZGWBMIModel.h"

#define kCurrentUserToken [[NSUserDefaults standardUserDefaults]objectForKey:@"token"]

@interface ZGWJiBingFengXianJiuZhengViewController ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, ZGWJiBingFengXianJiuZhengThireCellDelegate, ZGWJiBingFengXianJiuZhengFourThCellDelegate>

@property (nonatomic, strong) NSMutableArray *biaoTouNameArray; // 表头名字数组
@property (nonatomic, strong) NSMutableDictionary *biaoTouIsSelectDic; // 记录表头是否被点击

@property (nonatomic, strong) UITableView *jiBingJiuZhengTableView; // 疾病纠正tableView

@property (nonatomic, strong) NSMutableArray *userXinXiName; // 用户信息name

@property (nonatomic, strong) NSMutableDictionary *userXinXiNameDuiYingDic; // 用户信息name对应的dic

@property (nonatomic, strong) NSMutableArray *shengHuoXiGuanNameArray; //生活习惯name
@property (nonatomic, strong) NSMutableDictionary *shengHuoXiGuanNameDuiYingDic; // 生活习惯name对应的值

@property (nonatomic, strong) NSMutableArray *jiBingShiNameArray; // 疾病史name
@property (nonatomic, strong) NSMutableDictionary *jiBingShiNameDuiYingDic; // 疾病史name对应的值

@property (nonatomic, strong) NSIndexPath *tempIndexPath;

@property (nonatomic, strong) NSMutableArray *headerImageArray; // 表头图片数组

@property (nonatomic, strong) NSMutableArray *xiangGuanYinSuShengHuoXiGuanNameArray; // 相关致病因素的生活习惯name数组
@property (nonatomic, strong) NSMutableDictionary *xiangGuanYinSuShengHuoXiGuanDic; // 相关致病因素的生活习惯数组字典

@property (nonatomic, strong) NSMutableArray *xiangGuanYinSuJiBingShiNameArray; // 相关致病因素的疾病史name数组

@property (nonatomic, strong) NSMutableDictionary *xiangGuanYinSuJiBingDic; // 相关致病因素的疾病史字典

@property (nonatomic, strong) NSMutableDictionary *xiangGuanYinSuShengHuoXiGuanDuiYingCountDic; // 相关致病因素的生活习惯对应的数值

@property (nonatomic, strong) NSMutableDictionary *xiangGuanYinSuJiBingShiDuiYingCountDic; // 相关致病因素的疾病史对应的数值

@property (nonatomic, strong) NSMutableDictionary *userXinXiDuiYingCountDic; // 用户信息对应的数值字典

@property (nonatomic, assign) float jiuzhengFengXianZhiCount; // 纠正后风险值

@property (nonatomic, strong) NSString *ageText; // 年龄变化

@property (nonatomic, strong) NSString *shenGaoText; // 身高变化

@property (nonatomic, strong) NSString *tiZhongText; // 体重变化

@property (nonatomic, strong) NSTimer *myTimer; // 检查请求是否超时
@property (nonatomic, assign) NSInteger numberOfTime; // 存储请求时间

@property (nonatomic, assign) BOOL canClickFinish; // 是否可以点击完成

// 以下是真实数据的保存容器

@property (nonatomic, strong) NSMutableArray *zgwJiBingShiArray; // 疾病史数组

@property (nonatomic, strong) NSMutableArray *zgwShengHuoXiGuanArray; // 生活习惯数组

@property (nonatomic, strong) ZGWJiaZuShiModel *zgwJiaZuShiModel; // 家族史

@property (nonatomic, strong) ZGWAgeModel *zgwAgeModel; // 年龄

@property (nonatomic, strong) ZGWGenderModel *zgwGenderModel; // 性别

@property (nonatomic, strong) ZGWBMIModel *zgwBMIModel; // BMI

@property (nonatomic, strong) NSMutableArray *scoreArray; // 分数的数组，数组里面是字典，并且字典里面包含name、weight、socre

@property (nonatomic, strong) NSString *probility_modifiedString; // 纠正后的患病概率

@property (nonatomic, strong) NSString *risk_scoreString; // 纠正后风险指数

@end

@implementation ZGWJiBingFengXianJiuZhengViewController

- (void)viewWillDisappear:(BOOL)animated
{
    [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
    [self.myTimer invalidate];
    self.numberOfTime = 0;
    [super viewWillDisappear:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    // navi的修改
    [self changeNavigation];
    
    // 检查网络并建立数据源
    [self searchNetAndAddData];
    self.canClickFinish = YES;
}
// navi的修改
- (void)changeNavigation
{
    self.navigationItem.title = @"疾病风险矫正";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
    // 右方
    UIButton *finishButton = [UIButton buttonWithType:UIButtonTypeSystem];
    finishButton.frame = CGRectMake(0, 0, 50, 23);
    [finishButton setTitle:@"完成" forState:UIControlStateNormal];
    [finishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [finishButton addTarget:self action:@selector(finishFengXianJiuZheng:) forControlEvents:UIControlEventTouchUpInside];
    finishButton.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k16Big];
    finishButton.layer.borderWidth = 1 * kAdjustParamater;
    finishButton.layer.borderColor = [[UIColor whiteColor] CGColor];
    finishButton.layer.cornerRadius = 6 * kAdjustParamater;
    finishButton.layer.masksToBounds = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:finishButton];
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 完成
- (void)finishFengXianJiuZheng:(UIButton *)button
{
    NSLog(@"完成风险值纠正");
    NSInteger weiTianXieCount = 0; // 保存未填写的数量
    NSMutableString *weiTianXieString = [NSMutableString stringWithFormat:@""]; // 保存未填写因素的名字
    NSMutableArray *weiTianXieArray = [NSMutableArray array]; // 保存未填写的因素的数组
    // 判断是否有未填写的
    for (NSDictionary *tempDic in self.scoreArray) {
        if ([[tempDic valueForKey:@"weight"] isEqualToString:@"0"]) {
            weiTianXieCount++;
            [weiTianXieArray addObject:[tempDic valueForKey:@"name"]];
        }
    }
    for (int i = 0; i < weiTianXieArray.count; i++) {
        NSString *factorName = weiTianXieArray[i];
        NSString *result = @"";
        if ((weiTianXieArray.count - 1) == i) {
            result = [NSString stringWithFormat:@"%@  ", factorName];
        } else {
            result = [NSString stringWithFormat:@"%@、", factorName];
        }
        [weiTianXieString appendString:result];
    }
    
    if (weiTianXieCount == self.scoreArray.count) {
        // 说明什么也没有填写
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addNoDismissAlertWithTitle:@"提示" AndContent:@"您还未填写任何选项，不能提交" toView:self];
    } else if (weiTianXieCount < self.scoreArray.count && weiTianXieCount > 0) {
        // 说明有一部分未填写
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"致病因素:%@暂未填写，可能造成提交后结果不准确，您确定要提交么？", weiTianXieString] preferredStyle:UIAlertControllerStyleAlert];
        // 修改标题颜色
        NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:@"提示"];
        [titleString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
        [titleString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];
        [alertVC setValue:titleString forKey:@"attributedTitle"];
        UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"没有全部填完的提交");
            [self postRiskScore];
        }];
        [alertVC addAction:sureAction];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alertVC addAction:cancelAction];
        [self presentViewController:alertVC animated:YES completion:nil];
    } else if (weiTianXieCount == 0) {
        // 说明什么都填了
        NSLog(@"全部填完的提交");
        [self postRiskScore];
    }
    

//    if (self.isShiLiBaoGao == YES) {
//
//        NSInteger weiTianXieCount = 0; // 保存未填写的数量
//        NSMutableString *weiTianXieString = [NSMutableString stringWithFormat:@""]; // 保存未填写因素的名字
//        NSMutableArray *weiTianXieArray = [NSMutableArray array]; // 保存未填写的因素的数组
//        // 判断是否有未填写的
//        for (NSDictionary *tempDic in self.scoreArray) {
//            if ([[tempDic valueForKey:@"weight"] isEqualToString:@"0"]) {
//                weiTianXieCount++;
//                [weiTianXieArray addObject:[tempDic valueForKey:@"name"]];
//            }
//        }
//        for (int i = 0; i < weiTianXieArray.count; i++) {
//            NSString *factorName = weiTianXieArray[i];
//            NSString *result = @"";
//            if ((weiTianXieArray.count - 1) == i) {
//                 result = [NSString stringWithFormat:@"%@  ", factorName];
//            } else {
//                   result = [NSString stringWithFormat:@"%@、", factorName];
//            }
//            [weiTianXieString appendString:result];
//        }
//        
//        if (weiTianXieCount == self.scoreArray.count) {
//            // 说明什么也没有填写
//            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addNoDismissAlertWithTitle:@"提示" AndContent:@"您还未填写任何选项，不能提交" toView:self];
//        } else if (weiTianXieCount < self.scoreArray.count && weiTianXieCount > 0) {
//            // 说明有一部分未填写
//            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"致病因素:%@暂未填写，可能造成提交后结果不准确，您确定要提交么？", weiTianXieString] preferredStyle:UIAlertControllerStyleAlert];
//            // 修改标题颜色
//            NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:@"提示"];
//            [titleString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
//            [titleString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];
//            [alertVC setValue:titleString forKey:@"attributedTitle"];
//            UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                NSLog(@"没有全部填完的提交");
//                [self postRiskScore];
//            }];
//            [alertVC addAction:sureAction];
//            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//                
//            }];
//            [alertVC addAction:cancelAction];
//            [self presentViewController:alertVC animated:YES completion:nil];
//        } else if (weiTianXieCount == 0) {
//            // 说明什么都填了
//            NSLog(@"全部填完的提交");
//            [self postRiskScore];
//        }
//        
//        
//    } else {
//        // self.ZgwJiBingFengXianJiuZheng(3);
////        NSString *baiFenHao = @"%";
////        [NSString stringWithFormat:@"%f%@", self.jiuzhengFengXianZhiCount, baiFenHao];
////        self.ZgwJiBingFengXianJiuZheng(self.jiuzhengFengXianZhiCount);
////        [self.navigationController popViewControllerAnimated:YES];
//        
//        
//    }

}

#pragma mark - 进行修改风险值的提交
- (void)postRiskScore
{
    if (self.canClickFinish == YES) {
        self.canClickFinish = NO;
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] startAnimation];
        // 构建socre数组用于post提交
        NSMutableArray *scoresArray = [NSMutableArray array];
        for (NSDictionary *tempDic in self.scoreArray) {
            [scoresArray addObject:tempDic];
        }
        NSDictionary *scoresDic = [NSDictionary dictionaryWithObjectsAndKeys:scoresArray, @"scores", nil];
        
        // 纠正风险值的url
        NSString *jiuZhengFengXianZhiUrl = @"";
        if (self.isJianKangDangAnOrShiLiBaoGao == NO) {
            // 说明是健康大难
             jiuZhengFengXianZhiUrl = [NSString stringWithFormat:@"%@?token=%@", kZGWJianKangDangJiuZhengFengXianZhi, kCurrentUserToken];
        } else {
            // 说明是示例报告
             jiuZhengFengXianZhiUrl = [NSString stringWithFormat:@"%@?token=%@", kZGWMakeRiskChangeByRiskFactor, kCurrentUserToken];
            
        }
        NSLog(@"scoresDic = %@", scoresDic);
        NSDictionary *paramaterDic = @{@"id":self.recordID, @"content":[self dictionaryToJson:scoresDic]};
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:jiuZhengFengXianZhiUrl parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
            self.canClickFinish = YES;
        //    NSLog(@"responseObject = %@", responseObject);
            NSDictionary *statusDic = [responseObject valueForKey:@"status"];
            NSString *codeString = [NSString stringWithFormat:@"%@", [statusDic valueForKey:@"code"]];
            if ([codeString isEqualToString:@"0"]) {
              //  [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertNoTitieWithContent:@"风险值修改成功" toView:self];
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle]addAlertWithAnimationByTitle:@"风险值修改成功" toView:self];
                self.probility_modifiedString = [responseObject valueForKey:@"probility_modified"];
                self.risk_scoreString = [responseObject valueForKey:@"risk_score"];
                // 修改用户信息
                NSLog(@"纠正后风险指数%.2f", [self.risk_scoreString floatValue]);
                [self.userXinXiNameDuiYingDic setValue:[NSString stringWithFormat:@"%.2f", [self.risk_scoreString floatValue]] forKey:@"基因变异"];
                [self.jiBingJiuZhengTableView reloadData];
                // 健康档案界面需要刷新
                [[NetStatusHandle shareHandle] saveJianKangDangAnShouldRefresh:@"YES"];
                // block回调
                self.ZgwJiBingFengXianJiuZhengZhenData(self.probility_modifiedString, self.risk_scoreString);
                
            } else if ([codeString isEqualToString:@"1"]) {
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"纠正风险失败，请重试" ToView:self];
            }
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"纠正风险失败，请重试" ToView:self];
            self.canClickFinish = YES;
        }];

    }
    
}

#pragma mark - 检查网络并建立数据源
- (void)searchNetAndAddData
{
    if ([[[NetStatusHandle shareHandle] getNetStatus] isEqualToString:@"YES"]) {
        // 说明有网络
        // 建立数据源
        [self addData];
    
            // 说明不是示例报告
            // 建立计时器，计算是否超时
            self.myTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(goTimeOnJiuZhengFengXian:) userInfo:nil repeats:YES];
            [[NSRunLoop currentRunLoop] addTimer:self.myTimer forMode:NSRunLoopCommonModes];
            self.numberOfTime = 0;
            // 开始动画
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] startAnimation];
        
        // 说明有网络
        // 建立数据源
        [self addData];
        
        
    } else {
        NSLog(@"没有网络");
        // 添加提示框
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"通知" Content:kNoNetNoRefresh ToView:self];
    }
}

#pragma mark - 计时器方法
- (void)goTimeOnJiuZhengFengXian:(NSTimer *)timer
{
    self.numberOfTime++;
    NSLog(@"纠正风险时间= %ld", self.numberOfTime);
    if (self.numberOfTime > kZGWQingQiuChaoShi) {
        NSLog(@"纠正风险请求超时");
        self.numberOfTime = 0;
        [self.myTimer invalidate];
        // 关闭动画
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
        // 添加提示框
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"通知" Content:kQingQiuChaoShiNoReFresh ToView:self];
    }
}

#pragma mark - 添加数据源
- (void)addData
{
    if (self.isShiLiBaoGao == NO) {
        // 获取风险值因素url
        NSString *riskFactorUrl = [NSString stringWithFormat:@"%@?token=%@", kZGWGetInfluenceFactorOfDiease, kCurrentUserToken];
        NSDictionary *paramaterDic = @{@"single_disease_name":self.dieaseName};
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager GET:riskFactorUrl parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
            // 将计时器置为0
            self.numberOfTime = 0;
            [self.myTimer invalidate];
            // 结束动画
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
            if (!responseObject) {
                return;
            }
            
            // 初始化表头点击字典
            
            self.biaoTouNameArray = [NSMutableArray arrayWithObjects:@"我的基本资料", @"我的生活习惯", @"我的疾病史", nil];
            self.biaoTouIsSelectDic = [NSMutableDictionary dictionary];
            for (NSString *name in self.biaoTouNameArray) {
                [self.biaoTouIsSelectDic setValue:@"NO" forKey:name];
            }
            
            // 表头图片数组
            self.headerImageArray = [NSMutableArray arrayWithObjects:@"zhibingyinsu-jibingjiuzheng", @"jibenziliao-jibingjiuzheng", @"shenghuoxiguan-jibingjiuzheng", @"jibingshi-jibingjiuzheng", nil];
            
            // 初始化cell中要用到的数据
            // 用户基本信息都未选
            self.userXinXiName = [NSMutableArray array];
//            self.userXinXiNameDuiYingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:self.riskScore, @"基因变异" ,@"weiXuan", @"家族史", @"-1", @"年龄", @"weiXuan", @"性别", @"-1", @"BMI", @"-1", @"体重", nil];
            self.userXinXiNameDuiYingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"weiXuan", @"性别", @"-1", @"年龄", @"-1", @"身高", @"-1", @"体重", self.riskScore, @"基因变异", @"weiXuan", @"家族史", @"-1", @"BMI", @"-1", @"体脂率", nil];
            // 生活习惯
            self.xiangGuanYinSuShengHuoXiGuanNameArray = [NSMutableArray array];
            // 生活习惯数值
            self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic = [NSMutableDictionary dictionary];
            // 疾病史
            self.xiangGuanYinSuJiBingShiNameArray = [NSMutableArray array];
            // 疾病史数值
            self.xiangGuanYinSuJiBingShiDuiYingCountDic = [NSMutableDictionary dictionary];
            
            
            // 保存所有影响因素的名字的数组
            NSMutableArray *allInfluenceFactorArray = [NSMutableArray array];
            
            NSDictionary *factorDic = [responseObject valueForKey:@"factors"];
            // 疾病史
            NSArray *jiBingArray = [factorDic valueForKey:@"疾病史"];
            //  用户疾病史字典,分为-1、1、2、3，1代表严重，2代表轻微，3代表无，-1代表未选，默认为未选
            self.zgwJiBingShiArray = [NSMutableArray array];
            for (NSDictionary *tempDic in jiBingArray) {
                ZGWDieaseHistoryModel *model = [[ZGWDieaseHistoryModel alloc] init];
                [model setValuesForKeysWithDictionary:tempDic];
                [self.zgwJiBingShiArray addObject:model];
                [self.xiangGuanYinSuJiBingShiNameArray addObject:[tempDic valueForKey:@"factor"]];
                [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:@"-1" forKey:[tempDic valueForKey:@"factor"]];
                [allInfluenceFactorArray addObject:[tempDic valueForKey:@"factor"]];
            }
            
            // 生活习惯
            NSArray *shengHuoXiGuanArray = [factorDic valueForKey:@"生活习惯"];
              // 用户生活习惯字典,分为-1、0、1、2、3，0代表经常，1代表偶尔，2代表一般，3代表否，-1代表未选
            self.shengHuoXiGuanNameDuiYingDic = [NSMutableDictionary dictionary];
            self.zgwShengHuoXiGuanArray = [NSMutableArray array];
            for (NSDictionary *tempDic in shengHuoXiGuanArray) {
                ZGWShengHuoXiGuanModel *model = [[ZGWShengHuoXiGuanModel alloc] init];
                [model setValuesForKeysWithDictionary:tempDic];
                [self.zgwShengHuoXiGuanArray addObject:model];
                [self.xiangGuanYinSuShengHuoXiGuanNameArray addObject:[tempDic valueForKey:@"factor"]];
                [self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic setValue:@"-1" forKey:[tempDic valueForKey:@"factor"]];
                [allInfluenceFactorArray addObject:[tempDic valueForKey:@"factor"]];
            }
            
            
            
            
            // 家族史
            NSArray *jiaZuShiArray = [factorDic valueForKey:@"家族史"];
            if (jiaZuShiArray.count > 0) {
                self.zgwJiaZuShiModel = [[ZGWJiaZuShiModel alloc] init];
                [self.zgwJiaZuShiModel setValuesForKeysWithDictionary:jiaZuShiArray[0]];
                [allInfluenceFactorArray addObject:[jiaZuShiArray[0] valueForKey:@"factor"]];
            }
            
            // 年龄
            NSArray *ageArray = [factorDic valueForKey:@"年龄"];

            if (ageArray.count > 0) {
                  self.zgwAgeModel = [[ZGWAgeModel alloc] init];
                 [self.zgwAgeModel setValuesForKeysWithDictionary:ageArray[0]];
                [allInfluenceFactorArray addObject:[ageArray[0] valueForKey:@"factor"]];
            }
     
            
            // 性别
            NSArray *genderArray = [factorDic valueForKey:@"性别"];
            if (genderArray.count > 0) {
                self.zgwGenderModel = [[ZGWGenderModel alloc] init];
                 [self.zgwGenderModel setValuesForKeysWithDictionary:genderArray[0]];
                [allInfluenceFactorArray addObject:[genderArray[0] valueForKey:@"factor"]];
            }
            NSLog(@"self.GenderModel = %@,weight = %@,men = %@ ", self.zgwGenderModel, self.zgwGenderModel.weight,self.zgwGenderModel.men);
            
            // BMI
            NSArray *BMIArray = [factorDic valueForKey:@"BMI"];

            if (BMIArray.count > 0) {
                 self.zgwBMIModel = [[ZGWBMIModel alloc] init];
                      [self.zgwBMIModel setValuesForKeysWithDictionary:BMIArray[0]];
                [allInfluenceFactorArray addObject:[BMIArray[0] valueForKey:@"factor"]];
            }
            
            // 对初值进行初始化
            self.scoreArray = [NSMutableArray array];
            for (int i = 0; i < allInfluenceFactorArray.count; i++) {
                // 影响因素的名字
                NSString *factorName = allInfluenceFactorArray[i];
                NSMutableDictionary *factorDic = [NSMutableDictionary dictionary];
                [factorDic setValue:factorName forKey:@"name"];
                [factorDic setValue:@"0" forKey:@"weight"];
                [factorDic setValue:@"0" forKey:@"score"];
                [self.scoreArray addObject:factorDic];
            }
            
            // 布局
            [self addMySubview];
            
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            // 关闭动画
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
            // 添加提示框
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"通知" Content:@"相关内容获取失败请返回上一页重试" ToView:self];
            // 暂停计时器
            [self.myTimer invalidate];
            self.numberOfTime = 0;
        }];
        

    } else {
        // 将计时器置为0
        self.numberOfTime = 0;
        [self.myTimer invalidate];
        // 结束动画
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
        // 本地模拟数据
        [self addMoNiData];
        // 布局
        [self addMySubview];
    }
   
}

// 模拟数据
- (void)addMoNiData
{
    self.biaoTouNameArray = [NSMutableArray arrayWithObjects:@"我的基本资料", @"我的生活习惯", @"我的疾病史", nil];
    self.biaoTouIsSelectDic = [NSMutableDictionary dictionary];
    for (NSString *name in self.biaoTouNameArray) {
        [self.biaoTouIsSelectDic setValue:@"NO" forKey:name];
    }
    
    // 用户name
    self.userXinXiName = [NSMutableArray arrayWithObjects:@"性别", @"年龄", @"身高", @"体重", @"基因变异", @"家族史", @"BMI", @"体脂率", nil];
    // 用户信息字典
    self.userXinXiNameDuiYingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"women", @"性别", @"31", @"年龄", @"170", @"身高", @"60", @"体重", @"1.8", @"基因变异", @"一人", @"家族史", @"20.7", @"BMI", @"26.6", @"体脂率", nil];
    // 用户生活习惯name
    self.shengHuoXiGuanNameArray = [NSMutableArray arrayWithObjects:@"吸烟", @"喝酒", @"喝茶", @"喝咖啡", @"熬夜", @"焦虑", @"压力山大", @"适当锻炼", @"三餐规律", @"合理膳食", @"睡眠充足", @"喝水适量喝水适量喝水适量喝水适量", @"知足常乐知足常乐", nil];
    // 用户生活习惯字典,分为-1、0、1、2、3，0代表经常，1代表偶尔，2代表一般，3代表否，-1代表未选
    self.shengHuoXiGuanNameDuiYingDic = [NSMutableDictionary dictionary];
    for (NSString *shengHuoXiGuanString in self.shengHuoXiGuanNameArray) {
        // 默认为无
        [self.shengHuoXiGuanNameDuiYingDic setValue:@"2" forKey:shengHuoXiGuanString];
    }
    // 用户疾病史
    self.jiBingShiNameArray = [NSMutableArray arrayWithObjects:@"高血压", @"糖尿病", @"高血脂", @"低血糖", @"贫血", @"肾病", @"肝病", @"胃病", @"心脏病", @"心肌炎心肌炎心肌炎", @"支气管炎支气管炎", nil];
    // 用户疾病史字典,分为1、2、3，1代表严重，2代表轻微，3代表无
    self.jiBingShiNameDuiYingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1", @"高血压", @"2", @"糖尿病", @"3", @"高血脂", @"3", @"低血糖", @"2", @"贫血", @"3", @"肾病", @"2", @"肝病", @"1", @"胃病", @"1", @"心脏病", @"2", @"心肌炎心肌炎心肌炎", @"1", @"支气管炎支气管炎", nil];
    
    // 表头图片数组
    self.headerImageArray = [NSMutableArray arrayWithObjects:@"zhibingyinsu-jibingjiuzheng", @"jibenziliao-jibingjiuzheng", @"shenghuoxiguan-jibingjiuzheng", @"jibingshi-jibingjiuzheng", nil];
    
    
    // 提取相关致病因素需要展示的数据
    [self tiQuXiangGuanZhiBingYinSuData];
    
    [self simulateJiBingFengXianZhi];
}

#pragma mark - 提取相关致病因素需要展示的数据
- (void)tiQuXiangGuanZhiBingYinSuData
{
    // 吸烟的字典
    NSMutableDictionary *xiYanZiDian = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"经常", @"1", @"偶尔", @"0.5", @"否", nil];
    self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic = [NSMutableDictionary dictionary];
    // 相关致病因素的生活习惯name数组、dic
    self.xiangGuanYinSuShengHuoXiGuanNameArray = [NSMutableArray array];
    self.xiangGuanYinSuShengHuoXiGuanDic = [NSMutableDictionary dictionary];
    for (NSString *shengHuoName in self.shengHuoXiGuanNameArray) {
        if ([shengHuoName isEqualToString:@"吸烟"]) {
            [self.xiangGuanYinSuShengHuoXiGuanNameArray addObject:shengHuoName];
            [self.xiangGuanYinSuShengHuoXiGuanDic setValue:[self.shengHuoXiGuanNameDuiYingDic valueForKey:shengHuoName] forKey:shengHuoName];
            [self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic setValue:xiYanZiDian forKey:shengHuoName];
        }
    }
    
    // 相关致病因素的疾病史的name数组、dic
    // 高血压字典
    NSMutableDictionary *gaoXueYaDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"严重", @"1.2", @"轻微", @"1", @"无", nil];
    // 高血脂症字典
    NSMutableDictionary *gaoXueZhiZhengDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"严重", @"1.2", @"轻微", @"1", @"无", nil];
    // 糖尿病字典
    NSMutableDictionary *tangNiaoBingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"严重", @"1.2", @"轻微", @"1", @"无", nil];
    // 相关字典对应的数值
    self.xiangGuanYinSuJiBingShiDuiYingCountDic = [NSMutableDictionary dictionary];
    self.xiangGuanYinSuJiBingShiNameArray = [NSMutableArray array];
    self.xiangGuanYinSuJiBingDic = [NSMutableDictionary dictionary];
    for (NSString *jiBingShiName in self.jiBingShiNameDuiYingDic) {
        if ([jiBingShiName isEqualToString:@"高血压"]) {
            [self.xiangGuanYinSuJiBingShiNameArray addObject:jiBingShiName];
            [self.xiangGuanYinSuJiBingDic setValue:[self.jiBingShiNameDuiYingDic valueForKey:jiBingShiName] forKey:jiBingShiName];
            [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:gaoXueYaDic forKey:jiBingShiName];
        } else if ([jiBingShiName isEqualToString:@"高血脂"]) {
            [self.xiangGuanYinSuJiBingShiNameArray addObject:jiBingShiName];
            [self.xiangGuanYinSuJiBingDic setValue:[self.jiBingShiNameDuiYingDic valueForKey:jiBingShiName] forKey:jiBingShiName];
            [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:gaoXueZhiZhengDic forKey:jiBingShiName];
        } else if ([jiBingShiName isEqualToString:@"糖尿病"]) {
            [self.xiangGuanYinSuJiBingShiNameArray addObject:jiBingShiName];
            [self.xiangGuanYinSuJiBingDic setValue:[self.jiBingShiNameDuiYingDic valueForKey:jiBingShiName] forKey:jiBingShiName];
            [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:tangNiaoBingDic forKey:jiBingShiName];
        }
    }
    
    // 家族史对应数值字典
    NSMutableDictionary *jiaZuShiCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"多人", @"1.2", @"一人", @"1", @"无", nil];
    // 年龄对应的数值字典
    NSMutableDictionary *nianLingCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"0.5", @"<30", @"1.2", @"30-50", @"1.3", @">50", nil];
    // BMI指数对应数值字典
    NSMutableDictionary *BMIZhiShuCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @">28", @"1.2", @"24-28", @"0.8", @"18.5-24", @"0.5", @"<18.5", nil];
    // 性别对应数值字典
    NSMutableDictionary *genderCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1", @"男", @"0.5", @"女", nil];
    self.userXinXiDuiYingCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:jiaZuShiCountDic, @"家族史", nianLingCountDic, @"年龄", BMIZhiShuCountDic, @"BMI指数",genderCountDic, @"性别",  nil];
    //    NSLog(@"相关致病因素生活习惯对应的数值字典 = %@", self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic);
    //    NSLog(@"相关致病因素疾病史对应的数值字典 = %@", self.xiangGuanYinSuJiBingShiDuiYingCountDic);
    //    NSLog(@"用户信息对应的数值字典 = %@", self.userXinXiDuiYingCountDic);
    //
}

#pragma mark - 计算疾病风险值
- (void)simulateJiBingFengXianZhi
{
    // 家族史
    NSString *jiaZuShiString = [self.userXinXiNameDuiYingDic valueForKey:@"家族史"];
    float jiaZuShiCount = 0.0;
    if ([jiaZuShiString isEqualToString:@"多人"]) {
        jiaZuShiCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"家族史"] valueForKey:@"多人"] floatValue];
    } else if ([jiaZuShiString isEqualToString:@"一人"]) {
        jiaZuShiCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"家族史"] valueForKey:@"一人"] floatValue];
    } else if ([jiaZuShiString isEqualToString:@"无"]) {
        jiaZuShiCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"家族史"] valueForKey:@"无"] floatValue];
    }
    
    // 性别
    NSString *genderString = [self.userXinXiNameDuiYingDic valueForKey:@"性别"];
    float genderCount = 0.0;
    if ([genderString isEqualToString:@"men"]) {
        genderCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"性别"] valueForKey:@"男"] floatValue];
    } else if ([genderString isEqualToString:@"women"]) {
        genderCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"性别"] valueForKey:@"女"] floatValue];
    }
    
    // BMI指数
    float BMIString = [[self.userXinXiNameDuiYingDic valueForKey:@"BMI"] floatValue];
    float BMICount = 0.0;
    if (BMIString > 28) {
        BMICount = [[[self.userXinXiDuiYingCountDic valueForKey:@"BMI指数"] valueForKey:@">28"] floatValue];
    } else if (BMIString > 24 && BMIString <=28) {
        BMICount = [[[self.userXinXiDuiYingCountDic valueForKey:@"BMI指数"] valueForKey:@"24-28"] floatValue];
    } else if (BMIString >= 18.5 && BMIString <= 24) {
        BMICount = [[[self.userXinXiDuiYingCountDic valueForKey:@"BMI指数"] valueForKey:@"18.5-24"] floatValue];
    } else if (BMIString < 18.5) {
        BMICount = [[[self.userXinXiDuiYingCountDic valueForKey:@"BMI指数"] valueForKey:@"<18.5"] floatValue];
    }
    
    // 年龄
    float ageString = [[self.userXinXiNameDuiYingDic valueForKey:@"年龄"] floatValue];
    float ageCount = 0.0;
    if (ageString < 30) {
        ageCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"年龄"] valueForKey:@"<30"] floatValue];
    } else if (ageString >= 30 && ageString < 50) {
        ageCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"年龄"] valueForKey:@"30-50"] floatValue];
    } else if (ageString >= 50) {
        ageCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"年龄"] valueForKey:@">50"] floatValue];
    }
    
    // 吸烟
    NSString *xiYanString = [self.shengHuoXiGuanNameDuiYingDic valueForKey:@"吸烟"];
    float xiYanCount = 0.0;
    if ([xiYanString isEqualToString:@"1"]) {
        xiYanCount = [[[self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic valueForKey:@"吸烟"] valueForKey:@"经常"] floatValue];
    } else if ([xiYanString isEqualToString:@"2"]) {
        xiYanCount = [[[self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic valueForKey:@"吸烟"] valueForKey:@"偶尔"] floatValue];
    } else if ([xiYanString isEqualToString:@"3"]) {
        xiYanCount = [[[self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic valueForKey:@"吸烟"] valueForKey:@"否"] floatValue];
    }
    
    // 高血压
    NSString *gaoXueYaString = [self.jiBingShiNameDuiYingDic valueForKey:@"高血压"];
    float gaoXueCount = 0.0;
    if ([gaoXueYaString isEqualToString:@"1"]) {
        gaoXueCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血压"] valueForKey:@"严重"] floatValue];
    } else if ([gaoXueYaString isEqualToString:@"2"]) {
        gaoXueCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血压"] valueForKey:@"轻微"] floatValue];
    } else if ([gaoXueYaString isEqualToString:@"3"]) {
        gaoXueCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血压"] valueForKey:@"无"] floatValue];
    }
    
    // 高血脂
    NSString *gaoXueZhiString = [self.jiBingShiNameDuiYingDic valueForKey:@"高血脂"];
    float gaoXueZhiCount = 0.0;
    if ([gaoXueZhiString isEqualToString:@"1"]) {
        gaoXueZhiCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血脂"] valueForKey:@"严重"] floatValue];
    } else if ([gaoXueZhiString isEqualToString:@"2"]) {
        gaoXueZhiCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血脂"] valueForKey:@"轻微"] floatValue];
    } else if ([gaoXueZhiString isEqualToString:@"3"]) {
        gaoXueZhiCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血脂"] valueForKey:@"无"] floatValue];
    }
    
    // 糖尿病
    NSString *tangNiaoBingString = [self.jiBingShiNameDuiYingDic valueForKey:@"糖尿病"];
    float tangNiaoBingCount = 0.0;
    if ([tangNiaoBingString isEqualToString:@"1"]) {
        tangNiaoBingCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"糖尿病"] valueForKey:@"严重"] floatValue];
    } else if ([tangNiaoBingString isEqualToString:@"2"]) {
        tangNiaoBingCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"糖尿病"] valueForKey:@"轻微"] floatValue];
    } else if ([tangNiaoBingString isEqualToString:@"3"]) {
        tangNiaoBingCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"糖尿病"] valueForKey:@"无"] floatValue];
    }
    
    //    NSLog(@"家族史数值 = %f", jiaZuShiCount);
    //    NSLog(@"年龄数值 = %f", ageCount);
    //    NSLog(@"BMI数值 = %f", BMICount);
    //    NSLog(@"性别数值 = %f", genderCount);
    //    NSLog(@"吸烟数值 = %f", xiYanCount);
    //    NSLog(@"高血压数值 = %f", gaoXueCount);
    //    NSLog(@"高血脂数值 = %f", gaoXueZhiCount);
    //    NSLog(@"糖尿病数值 = %f", tangNiaoBingCount);
    // 基因变异指数
    float jiYinBianYiCount = [[self.userXinXiNameDuiYingDic valueForKey:@"基因变异"] floatValue];
    self.jiuzhengFengXianZhiCount = jiYinBianYiCount * jiaZuShiCount * ageCount * BMICount * genderCount * xiYanCount * gaoXueCount * gaoXueZhiCount * tangNiaoBingCount;
    NSLog(@"纠正风险值数值 = %f", self.jiuzhengFengXianZhiCount);
}

#pragma mark - 布局
- (void)addMySubview
{
    self.jiBingJiuZhengTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) style:UITableViewStylePlain];
    self.jiBingJiuZhengTableView.backgroundColor = [UIColor whiteColor];
    self.jiBingJiuZhengTableView.dataSource = self;
    self.jiBingJiuZhengTableView.delegate = self;
    self.jiBingJiuZhengTableView.bounces = NO;
    self.jiBingJiuZhengTableView.showsVerticalScrollIndicator = NO;
    self.jiBingJiuZhengTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_jiBingJiuZhengTableView];
    
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.isShiLiBaoGao == NO) {
        if (section == 0) {
            return 1;
        } else {
            NSString *name = self.biaoTouNameArray[section - 1];
            NSString *isSelect = [self.biaoTouIsSelectDic valueForKey:name];
            if ([isSelect isEqualToString:@"YES"]) {
                return 1;
            } else if ([isSelect isEqualToString:@"NO"]) {
                return 0;
            }
        }
    } else  {
        if (section == 0) {
            return 1;
        } else {
            NSString *name = self.biaoTouNameArray[section - 1];
            NSString *isSelect = [self.biaoTouIsSelectDic valueForKey:name];
            if ([isSelect isEqualToString:@"YES"]) {
                return 1;
            } else if ([isSelect isEqualToString:@"NO"]) {
                return 0;
            }
        }
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.isShiLiBaoGao == NO) {
        if (indexPath.section == 0) {
            // 相关致病因素cell
            static NSString *identifier = @"firstCell";
            ZGWJiBingFengXianJiuZhengFirstTableViewCell *firstCell = [[ZGWJiBingFengXianJiuZhengFirstTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withZhenUserXinXiNameArray:self.userXinXiName userXinXiDic:self.userXinXiNameDuiYingDic shengHuoXiGuanNameArray:self.xiangGuanYinSuShengHuoXiGuanNameArray shengHuoXiGuanDic:self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic jiBingShiNameArray:self.xiangGuanYinSuJiBingShiNameArray jiBingShiDic:self.xiangGuanYinSuJiBingShiDuiYingCountDic];
            firstCell.selectionStyle = UITableViewCellSelectionStyleNone;
            [firstCell.duoRenButtonOfJiaZuShi addTarget:self action:@selector(duoRenOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
            [firstCell.yiRenButtonOfJiaZuShi addTarget:self action:@selector(yiRenOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
            [firstCell.wuButtonOfJiaZuShi addTarget:self action:@selector(wuButtonOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
            return firstCell;
        } else if (indexPath.section == 1) {
            self.tempIndexPath = indexPath;
            // 我的基本资料
            static NSString *identifier = @"secondCell";
            ZGWJiBingFengXianJiuZhengSecondTableViewCell *secondCell = [[ZGWJiBingFengXianJiuZhengSecondTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withZhenUserXinXiDic:self.userXinXiNameDuiYingDic];
            secondCell.selectionStyle = UITableViewCellSelectionStyleNone;
            [secondCell.nanButton addTarget:self action:@selector(nanOfSecondCell:) forControlEvents:UIControlEventTouchUpInside];
            [secondCell.nvButton addTarget:self action:@selector(nvOfSecondCell:) forControlEvents:UIControlEventTouchUpInside];
            secondCell.ageTF.delegate = self;
            secondCell.ageTF.tag = 300;
            [secondCell.ageTF addTarget:self action:@selector(textChangeOfSecondCell1:) forControlEvents:UIControlEventAllEditingEvents];
            // 为年龄添加辅助视图
            // 构建辅助视图
            UIView *seorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
            seorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
            
            UILabel *grayLineOnSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
            grayLineOnSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
            [seorryView addSubview:grayLineOnSeorryView];
            
            // 完成button
            UIButton *textViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
            textViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
            textViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
            [textViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
            [textViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            textViewFinishButton.backgroundColor = kCyanColor;
            textViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
            [textViewFinishButton addTarget:self action:@selector(ageFinish:) forControlEvents:UIControlEventTouchUpInside];
            [seorryView addSubview:textViewFinishButton];
            secondCell.ageTF.inputAccessoryView = seorryView;
            
            secondCell.shenGaoTF.delegate = self;
            secondCell.shenGaoTF.tag = 301;
            [secondCell.shenGaoTF addTarget:self action:@selector(textChangeOfSecondCell2:) forControlEvents:UIControlEventAllEditingEvents];
            // 为身高添加辅助视图
            // 构建辅助视图
            UIView *shenGaoseorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
            shenGaoseorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
            
            UILabel *grayLineOnShenGaoSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
            grayLineOnShenGaoSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
            [shenGaoseorryView addSubview:grayLineOnShenGaoSeorryView];
            
            // 完成button
            UIButton *shenGaoTextViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
            shenGaoTextViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
            shenGaoTextViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
            [shenGaoTextViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
            [shenGaoTextViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            shenGaoTextViewFinishButton.backgroundColor = kCyanColor;
            shenGaoTextViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
            [shenGaoTextViewFinishButton addTarget:self action:@selector(shenGaoFinish:) forControlEvents:UIControlEventTouchUpInside];
            [shenGaoseorryView addSubview:shenGaoTextViewFinishButton];
            secondCell.shenGaoTF.inputAccessoryView = shenGaoseorryView;
            
            
            secondCell.tiZhongTF.delegate = self;
            secondCell.tiZhongTF.tag = 302;
            [secondCell.tiZhongTF addTarget:self action:@selector(textChangeOfSecondCell3:) forControlEvents:UIControlEventAllEditingEvents];
            // 为体重添加辅助视图
            // 构建辅助视图
            UIView *tiZhongseorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
            tiZhongseorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
            
            UILabel *grayLineOnTiZhongSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
            grayLineOnTiZhongSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
            [tiZhongseorryView addSubview:grayLineOnTiZhongSeorryView];
            
            // 完成button
            UIButton *tiZhongTextViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
            tiZhongTextViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
            tiZhongTextViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
            [tiZhongTextViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
            [tiZhongTextViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            tiZhongTextViewFinishButton.backgroundColor = kCyanColor;
            tiZhongTextViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
            [tiZhongTextViewFinishButton addTarget:self action:@selector(tiZhongFinish:) forControlEvents:UIControlEventTouchUpInside];
            [tiZhongseorryView addSubview:tiZhongTextViewFinishButton];
            secondCell.tiZhongTF.inputAccessoryView = tiZhongseorryView;
            return secondCell;
        } else if (indexPath.section == 2) {
            // 我的生活习惯
            static NSString *identifier = @"thirdCell";
            ZGWJiBingFengXianJiuZhengThirdTableViewCell *thirdCell = [[ZGWJiBingFengXianJiuZhengThirdTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withZhenShengHuoXiGuanNameArray:self.xiangGuanYinSuShengHuoXiGuanNameArray shengHuoXiGuanDic:self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic];
            thirdCell.selectionStyle = UITableViewCellSelectionStyleNone;
            thirdCell.delegate = self;
            return thirdCell;
        } else if (indexPath.section == 3) {
            // 我的疾病史
            static NSString *identifier = @"fourthCell";
            ZGWJiBingFengXianJiuZhengFourthTableViewCell *fourThCell = [[ZGWJiBingFengXianJiuZhengFourthTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withZhenJiBingShiNameArray:self.xiangGuanYinSuJiBingShiNameArray jiBingShiDic:self.xiangGuanYinSuJiBingShiDuiYingCountDic];
            fourThCell.delegate = self;
            fourThCell.selectionStyle = UITableViewCellSelectionStyleNone;
            return fourThCell;
        }
    } else {
        if (indexPath.section == 0) {
            // 相关致病因素cell
            static NSString *identifier = @"firstCell";
            ZGWJiBingFengXianJiuZhengFirstTableViewCell *firstCell = [[ZGWJiBingFengXianJiuZhengFirstTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withUserXinXiNameArray:self.userXinXiName userXinXiDic:self.userXinXiNameDuiYingDic shengHuoXiGuanNameArray:self.xiangGuanYinSuShengHuoXiGuanNameArray shengHuoXiGuanDic:self.xiangGuanYinSuShengHuoXiGuanDic jiBingShiNameArray:self.xiangGuanYinSuJiBingShiNameArray jiBingShiDic:self.xiangGuanYinSuJiBingDic];
            firstCell.selectionStyle = UITableViewCellSelectionStyleNone;
            [firstCell.duoRenButtonOfJiaZuShi addTarget:self action:@selector(duoRenOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
            [firstCell.yiRenButtonOfJiaZuShi addTarget:self action:@selector(yiRenOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
            [firstCell.wuButtonOfJiaZuShi addTarget:self action:@selector(wuButtonOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
            return firstCell;
        } else if (indexPath.section == 1) {
            self.tempIndexPath = indexPath;
            // 我的基本资料
            static NSString *identifier = @"secondCell";
            ZGWJiBingFengXianJiuZhengSecondTableViewCell *secondCell = [[ZGWJiBingFengXianJiuZhengSecondTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withUserXinXiDic:self.userXinXiNameDuiYingDic];
            secondCell.selectionStyle = UITableViewCellSelectionStyleNone;
            [secondCell.nanButton addTarget:self action:@selector(nanOfSecondCell:) forControlEvents:UIControlEventTouchUpInside];
            [secondCell.nvButton addTarget:self action:@selector(nvOfSecondCell:) forControlEvents:UIControlEventTouchUpInside];
            secondCell.ageTF.delegate = self;
            secondCell.ageTF.tag = 300;
            [secondCell.ageTF addTarget:self action:@selector(textChangeOfSecondCell1:) forControlEvents:UIControlEventAllEditingEvents];
            // 为年龄添加辅助视图
            // 构建辅助视图
            UIView *seorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
            seorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
            
            UILabel *grayLineOnSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
            grayLineOnSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
            [seorryView addSubview:grayLineOnSeorryView];
            
            // 完成button
            UIButton *textViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
            textViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
            textViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
            [textViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
            [textViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            textViewFinishButton.backgroundColor = kCyanColor;
            textViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
            [textViewFinishButton addTarget:self action:@selector(ageFinish:) forControlEvents:UIControlEventTouchUpInside];
            [seorryView addSubview:textViewFinishButton];
            secondCell.ageTF.inputAccessoryView = seorryView;
            
            secondCell.shenGaoTF.delegate = self;
            secondCell.shenGaoTF.tag = 301;
            [secondCell.shenGaoTF addTarget:self action:@selector(textChangeOfSecondCell2:) forControlEvents:UIControlEventAllEditingEvents];
            // 为身高添加辅助视图
            // 构建辅助视图
            UIView *shenGaoseorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
            shenGaoseorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
            
            UILabel *grayLineOnShenGaoSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
            grayLineOnShenGaoSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
            [shenGaoseorryView addSubview:grayLineOnShenGaoSeorryView];
            
            // 完成button
            UIButton *shenGaoTextViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
            shenGaoTextViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
            shenGaoTextViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
            [shenGaoTextViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
            [shenGaoTextViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            shenGaoTextViewFinishButton.backgroundColor = kCyanColor;
            shenGaoTextViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
            [shenGaoTextViewFinishButton addTarget:self action:@selector(shenGaoFinish:) forControlEvents:UIControlEventTouchUpInside];
            [shenGaoseorryView addSubview:shenGaoTextViewFinishButton];
            secondCell.shenGaoTF.inputAccessoryView = shenGaoseorryView;
            
            
            secondCell.tiZhongTF.delegate = self;
            secondCell.tiZhongTF.tag = 302;
            [secondCell.tiZhongTF addTarget:self action:@selector(textChangeOfSecondCell3:) forControlEvents:UIControlEventAllEditingEvents];
            // 为体重添加辅助视图
            // 构建辅助视图
            UIView *tiZhongseorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
            tiZhongseorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
            
            UILabel *grayLineOnTiZhongSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
            grayLineOnTiZhongSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
            [tiZhongseorryView addSubview:grayLineOnTiZhongSeorryView];
            
            // 完成button
            UIButton *tiZhongTextViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
            tiZhongTextViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
            tiZhongTextViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
            [tiZhongTextViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
            [tiZhongTextViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            tiZhongTextViewFinishButton.backgroundColor = kCyanColor;
            tiZhongTextViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
            [tiZhongTextViewFinishButton addTarget:self action:@selector(tiZhongFinish:) forControlEvents:UIControlEventTouchUpInside];
            [tiZhongseorryView addSubview:tiZhongTextViewFinishButton];
            secondCell.tiZhongTF.inputAccessoryView = tiZhongseorryView;
            return secondCell;
        } else if (indexPath.section == 2) {
            // 我的生活习惯
            static NSString *identifier = @"thirdCell";
            ZGWJiBingFengXianJiuZhengThirdTableViewCell *thirdCell = [[ZGWJiBingFengXianJiuZhengThirdTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withShengHuoXiGuanNameArray:self.shengHuoXiGuanNameArray shengHuoXiGuanDic:self.shengHuoXiGuanNameDuiYingDic];
            thirdCell.selectionStyle = UITableViewCellSelectionStyleNone;
            thirdCell.delegate = self;
            return thirdCell;
        } else if (indexPath.section == 3) {
            // 我的疾病史
            static NSString *identifier = @"fourthCell";
            ZGWJiBingFengXianJiuZhengFourthTableViewCell *fourThCell = [[ZGWJiBingFengXianJiuZhengFourthTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withJiBingShiNameArray:self.jiBingShiNameArray jiBingShiDic:self.jiBingShiNameDuiYingDic];
            fourThCell.delegate = self;
            fourThCell.selectionStyle = UITableViewCellSelectionStyleNone;
            return fourThCell;
        }

    }
        // 没有这种情况
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        // 相关致病因素
        ZGWJiBingFengXianJiuZhengFirstTableViewCell *firstCell = (ZGWJiBingFengXianJiuZhengFirstTableViewCell *)[self tableView:self.jiBingJiuZhengTableView cellForRowAtIndexPath:indexPath];
        return firstCell.bottomGrayLine.bottom;
    } else if (indexPath.section == 1) {
        // 我的基本资料
        ZGWJiBingFengXianJiuZhengSecondTableViewCell *secondCell = (ZGWJiBingFengXianJiuZhengSecondTableViewCell *)[self tableView:self.jiBingJiuZhengTableView cellForRowAtIndexPath:indexPath];
        return secondCell.bottomGrayLabel.bottom;
    } else if (indexPath.section == 2) {
        // 我的生活习惯
        ZGWJiBingFengXianJiuZhengThirdTableViewCell *thirdCell = (ZGWJiBingFengXianJiuZhengThirdTableViewCell *)[self tableView:self.jiBingJiuZhengTableView cellForRowAtIndexPath:indexPath];
        return thirdCell.bottomGrayLine.bottom;
    } else if (indexPath.section == 3) {
        // 我的疾病史
        ZGWJiBingFengXianJiuZhengFourthTableViewCell *fourCell = (ZGWJiBingFengXianJiuZhengFourthTableViewCell *)[self tableView:self.jiBingJiuZhengTableView cellForRowAtIndexPath:indexPath];
        return fourCell.bottomGrayLine.bottom;
    }
    // 没有这种情况
    return 0 * kAdjustParamater;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        UIView *headerBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 67 * kAdjustParamater)];
        headerBackGroundView.backgroundColor = [UIColor whiteColor];
        
        // 标题之前的箭头
        UIImageView *biaoTiBeforeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(23 * kAdjustParamater, 25 * kAdjustParamater, 16 * kAdjustParamater, 16 * kAdjustParamater)];
        biaoTiBeforeImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        biaoTiBeforeImageV.layer.cornerRadius = biaoTiBeforeImageV.width / 2;
        biaoTiBeforeImageV.image = [UIImage imageNamed:self.headerImageArray[section]];
        [headerBackGroundView addSubview:biaoTiBeforeImageV];
        
        // 标题
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(biaoTiBeforeImageV.right + 6 * kAdjustParamater, 23 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
        titleLabel.text = @"冠心病相关致病因素";
        //   titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        titleLabel.textColor = kCyanColor;
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k20Big];
        [headerBackGroundView addSubview:titleLabel];
        
        // 添加灰色条
        UILabel *grayLineOnHeaderBottom = [[UILabel alloc] initWithFrame:CGRectMake(0, 66 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
        grayLineOnHeaderBottom.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.07];
        [headerBackGroundView addSubview:grayLineOnHeaderBottom];
        
        return headerBackGroundView;
    } else {
        UIView *headerBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 67 * kAdjustParamater)];
        headerBackGroundView.userInteractionEnabled = YES;
        headerBackGroundView.tag = 200 + section;
        headerBackGroundView.backgroundColor = [UIColor whiteColor];
        
        UITapGestureRecognizer *headerBackGroundViewTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headerBackGroundViewGes:)];
        [headerBackGroundView addGestureRecognizer:headerBackGroundViewTapGes];
        
        // 标题之前的箭头
        UIImageView *biaoTiBeforeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(23 * kAdjustParamater, 25 * kAdjustParamater, 16 * kAdjustParamater, 16 * kAdjustParamater)];
        biaoTiBeforeImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        biaoTiBeforeImageV.layer.cornerRadius = biaoTiBeforeImageV.width / 2;
        biaoTiBeforeImageV.image = [UIImage imageNamed:self.headerImageArray[section]];
        [headerBackGroundView addSubview:biaoTiBeforeImageV];
        
        // 标题
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(biaoTiBeforeImageV.right + 6 * kAdjustParamater, 23 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
        titleLabel.text = self.biaoTouNameArray[section - 1];
        //    titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        titleLabel.textColor = kCyanColor;
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k20Big];
        [headerBackGroundView addSubview:titleLabel];
        
        // 箭头
        UIImageView *jianTouImageV =  [[UIImageView alloc] initWithFrame:CGRectMake(340 * kAdjustParamater, 20 * kAdjustParamater, 25 * kAdjustParamater, 25 * kAdjustParamater)];
        NSString *name = self.biaoTouNameArray[section -1];
        // 是否点击
        NSString *isSelect = [self.biaoTouIsSelectDic valueForKey:name];
        if ([isSelect isEqualToString:@"YES"]) {
            jianTouImageV.image = [UIImage imageNamed:@"cyanjiantou-createGroup"];
        } else if ([isSelect isEqualToString:@"NO"]) {
            jianTouImageV.image = [UIImage imageNamed:@"huisejiantou-createGroup"];
        }
        [headerBackGroundView addSubview:jianTouImageV];
        
        // 添加灰色条
        UILabel *grayLineOnHeaderBottom = [[UILabel alloc] initWithFrame:CGRectMake(0, 66 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
        grayLineOnHeaderBottom.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.07];
        [headerBackGroundView addSubview:grayLineOnHeaderBottom];
        
        return headerBackGroundView;
    }
    return nil;
    // 为了截图
//    if (section == 0) {
//        UIView *headerBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 45 * kAdjustParamater)];
//        headerBackGroundView.backgroundColor = [UIColor whiteColor];
//        
//        // 标题之前的箭头
//        UIImageView *biaoTiBeforeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(23 * kAdjustParamater,  15 * kAdjustParamater, 16 * kAdjustParamater, 16 * kAdjustParamater)];
//        biaoTiBeforeImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
//        biaoTiBeforeImageV.layer.cornerRadius = biaoTiBeforeImageV.width / 2;
//        biaoTiBeforeImageV.image = [UIImage imageNamed:self.headerImageArray[section]];
//        [headerBackGroundView addSubview:biaoTiBeforeImageV];
//        
//        // 标题
//        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(biaoTiBeforeImageV.right + 6 * kAdjustParamater, 12 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
//        titleLabel.text = @"冠心病相关致病因素";
//        //   titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
//        titleLabel.textColor = kCyanColor;
//        titleLabel.textAlignment = NSTextAlignmentLeft;
//        titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k20Big];
//        [headerBackGroundView addSubview:titleLabel];
//        
//        // 添加灰色条
//        UILabel *grayLineOnHeaderBottom = [[UILabel alloc] initWithFrame:CGRectMake(0, 44 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
//        grayLineOnHeaderBottom.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.07];
//        [headerBackGroundView addSubview:grayLineOnHeaderBottom];
//        
//        return headerBackGroundView;
//    } else {
//        UIView *headerBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 45 * kAdjustParamater)];
//        headerBackGroundView.userInteractionEnabled = YES;
//        headerBackGroundView.tag = 200 + section;
//        headerBackGroundView.backgroundColor = [UIColor whiteColor];
//        
//        UITapGestureRecognizer *headerBackGroundViewTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headerBackGroundViewGes:)];
//        [headerBackGroundView addGestureRecognizer:headerBackGroundViewTapGes];
//        
//        // 标题之前的箭头
//        UIImageView *biaoTiBeforeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(23 * kAdjustParamater, 15 * kAdjustParamater, 16 * kAdjustParamater, 16 * kAdjustParamater)];
//        biaoTiBeforeImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
//        biaoTiBeforeImageV.layer.cornerRadius = biaoTiBeforeImageV.width / 2;
//        biaoTiBeforeImageV.image = [UIImage imageNamed:self.headerImageArray[section]];
//        [headerBackGroundView addSubview:biaoTiBeforeImageV];
//        
//        // 标题
//        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(biaoTiBeforeImageV.right + 6 * kAdjustParamater, 12 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
//        titleLabel.text = self.biaoTouNameArray[section - 1];
//        //    titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
//        titleLabel.textColor = kCyanColor;
//        titleLabel.textAlignment = NSTextAlignmentLeft;
//        titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k20Big];
//        [headerBackGroundView addSubview:titleLabel];
//        
//        // 箭头
//        UIImageView *jianTouImageV =  [[UIImageView alloc] initWithFrame:CGRectMake(340 * kAdjustParamater, 10 * kAdjustParamater, 25 * kAdjustParamater, 25 * kAdjustParamater)];
//        NSString *name = self.biaoTouNameArray[section -1];
//        // 是否点击
//        NSString *isSelect = [self.biaoTouIsSelectDic valueForKey:name];
//        if ([isSelect isEqualToString:@"YES"]) {
//            jianTouImageV.image = [UIImage imageNamed:@"cyanjiantou-createGroup"];
//        } else if ([isSelect isEqualToString:@"NO"]) {
//            jianTouImageV.image = [UIImage imageNamed:@"huisejiantou-createGroup"];
//        }
//        [headerBackGroundView addSubview:jianTouImageV];
//        
//        // 添加灰色条
//        UILabel *grayLineOnHeaderBottom = [[UILabel alloc] initWithFrame:CGRectMake(0, 44 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
//        grayLineOnHeaderBottom.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.07];
//        [headerBackGroundView addSubview:grayLineOnHeaderBottom];
//        
//        return headerBackGroundView;
//    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 67 * kAdjustParamater;
    // 为了截图
  //  return 45 * kAdjustParamater;
}

#pragma mark - 点击表头
- (void)headerBackGroundViewGes:(UITapGestureRecognizer *)tapGes
{
    NSLog(@"点击了第%ld行", tapGes.view.tag - 201);
    NSString *name = self.biaoTouNameArray[tapGes.view.tag - 201];
    NSString *isSelect = [self.biaoTouIsSelectDic valueForKey:name];
    if ([isSelect isEqualToString:@"YES"]) {
        [self.biaoTouIsSelectDic setValue:@"NO" forKey:name];
    } else if ([isSelect isEqualToString:@"NO"]) {
        [self.biaoTouIsSelectDic setValue:@"YES" forKey:name];
    }
    [self.jiBingJiuZhengTableView reloadData];
}

#pragma mark - 输出对中权值
- (void)outputScoreArray
{
    NSLog(@"scoreArray  = %@", [self descriptionWithLocale:self.scoreArray]);
}

#pragma mark - 致病因素cell
- (void)duoRenOfFirstCell:(UIButton *)button
{
    NSLog(@"多人");
    if (self.isShiLiBaoGao == NO) {
        [self.userXinXiNameDuiYingDic setValue:@"多人" forKey:@"家族史"];
        [self.jiBingJiuZhengTableView reloadData];
        // 取出多人的权重和数值
        for (int i = 0; i < self.scoreArray.count; i++) {
            NSMutableDictionary *tempDic = self.scoreArray[i];
            if ([[tempDic valueForKey:@"name"] isEqualToString:@"家族史"]) {
                [tempDic setValue:self.zgwJiaZuShiModel.weight forKey:@"weight"];
                [tempDic setValue:self.zgwJiaZuShiModel.more forKey:@"score"];
            }
        }
        [self outputScoreArray];
    } else {
        [self.userXinXiNameDuiYingDic setValue:@"多人" forKey:@"家族史"];
        [self.jiBingJiuZhengTableView reloadData];
        // 计算纠正风险值
        [self simulateJiBingFengXianZhi];
    }
}

- (void)yiRenOfFirstCell:(UIButton *)button
{
    NSLog(@"一人");
    if (self.isShiLiBaoGao == NO) {
        [self.userXinXiNameDuiYingDic setValue:@"一人" forKey:@"家族史"];
        [self.jiBingJiuZhengTableView reloadData];
        // 取出一人的权重和数值
        for (int i = 0; i < self.scoreArray.count; i++) {
            NSMutableDictionary *tempDic = self.scoreArray[i];
            if ([[tempDic valueForKey:@"name"] isEqualToString:@"家族史"]) {
                [tempDic setValue:self.zgwJiaZuShiModel.weight forKey:@"weight"];
                [tempDic setValue:self.zgwJiaZuShiModel.one forKey:@"score"];
            }
        }
        [self outputScoreArray];
    } else {
        [self.userXinXiNameDuiYingDic setValue:@"一人" forKey:@"家族史"];
        [self.jiBingJiuZhengTableView reloadData];
        // 计算纠正风险值
        [self simulateJiBingFengXianZhi];
    }
   
}

- (void)wuButtonOfFirstCell:(UIButton *)button
{
    NSLog(@"无人");
    if (self.isShiLiBaoGao == NO) {
        [self.userXinXiNameDuiYingDic setValue:@"无" forKey:@"家族史"];
        [self.jiBingJiuZhengTableView reloadData];
        // 取出无人的权重和数值
        for (int i = 0; i < self.scoreArray.count; i++) {
            NSMutableDictionary *tempDic = self.scoreArray[i];
            if ([[tempDic valueForKey:@"name"] isEqualToString:@"家族史"]) {
                [tempDic setValue:self.zgwJiaZuShiModel.weight forKey:@"weight"];
                [tempDic setValue:self.zgwJiaZuShiModel.without forKey:@"score"];
            }
        }
        [self outputScoreArray];
    } else {
        [self.userXinXiNameDuiYingDic setValue:@"无" forKey:@"家族史"];
        [self.jiBingJiuZhengTableView reloadData];
        // 计算纠正风险值
        [self simulateJiBingFengXianZhi];
    }

}

#pragma mark - 我的基本资料
- (void)nanOfSecondCell:(UIButton *)button
{
    NSLog(@"男");
    if (self.isShiLiBaoGao == NO) {
        [self.userXinXiNameDuiYingDic setValue:@"men" forKey:@"性别"];
        // 取出性别的权重和数值
        for (int i = 0; i < self.scoreArray.count; i++) {
            NSMutableDictionary *tempDic = self.scoreArray[i];
            if ([[tempDic valueForKey:@"name"] isEqualToString:@"性别"]) {
                if (self.zgwGenderModel != nil) {
                    [tempDic setValue:self.zgwGenderModel.weight forKey:@"weight"];
                    [tempDic setValue:self.zgwGenderModel.men forKey:@"score"];
                } else  {
                    [tempDic setValue:@"0" forKey:@"weight"];
                    [tempDic setValue:@"0" forKey:@"score"];
                }
            }
        }
        // 计算体脂率
        [self simulateTiZhiLv];
        [self.jiBingJiuZhengTableView reloadData];
        [self outputScoreArray];
    } else {
        [self.userXinXiNameDuiYingDic setValue:@"men" forKey:@"性别"];
        // 计算纠正风险值
        [self simulateJiBingFengXianZhi];
        // 计算体脂率
        [self simulateTiZhiLv];
        [self.jiBingJiuZhengTableView reloadData];
    }
 
}

- (void)nvOfSecondCell:(UIButton *)button
{
    NSLog(@"女");
    if (self.isShiLiBaoGao == NO) {
        [self.userXinXiNameDuiYingDic setValue:@"women" forKey:@"性别"];
        // 取出性别的权重和数值
        for (int i = 0; i < self.scoreArray.count; i++) {
            NSMutableDictionary *tempDic = self.scoreArray[i];
            if ([[tempDic valueForKey:@"name"] isEqualToString:@"性别"]) {
                if (self.zgwGenderModel != nil) {
                    [tempDic setValue:self.zgwGenderModel.weight forKey:@"weight"];
                    [tempDic setValue:self.zgwGenderModel.women forKey:@"score"];
                } else  {
                    [tempDic setValue:@"0" forKey:@"weight"];
                    [tempDic setValue:@"0" forKey:@"score"];
                }
            }
        }
        // 计算体脂率
        [self simulateTiZhiLv];
        [self.jiBingJiuZhengTableView reloadData];
        [self outputScoreArray];
    } else {
        [self.userXinXiNameDuiYingDic setValue:@"women" forKey:@"性别"];
        // 计算纠正风险值
        [self simulateJiBingFengXianZhi];
        // 计算体脂率
        [self simulateTiZhiLv];
        [self.jiBingJiuZhengTableView reloadData];
    }
   
}

#pragma mark - 我的基本资料TFdelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (self.isShiLiBaoGao == YES) {
        if (textField.tag == 302) {
            NSString *resultString = [textField.text substringToIndex:textField.text.length - 2];
            textField.text = resultString;
            
        }
    }
}

- (void)textChangeOfSecondCell1:(UITextField *)textField
{
    
    NSLog(@"年龄tf = %@", textField.text);
    self.ageText = textField.text;
}

- (void)textChangeOfSecondCell2:(UITextField *)textField
{
    
    
    NSLog(@"身高tf = %@", textField.text);
    self.shenGaoText = textField.text;
}

- (void)textChangeOfSecondCell3:(UITextField *)textField
{
    
    NSLog(@"体重tf = %@", textField.text);
    if ([textField.text containsString:@"kg"]) {
        NSString *resultString = [textField.text substringToIndex:textField.text.length - 2];
        self.tiZhongText = resultString;
    } else {
        self.tiZhongText = textField.text;
    }
    
}

- (void)ageFinish:(UIButton *)button
{
    NSLog(@"保存年龄");
    if (self.isShiLiBaoGao == NO) {
        // 取消第一响应者
        [self.view endEditing:YES];
        if ([self.ageText containsString:@" "]) {
            NSLog(@"不能输入空格");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
        } else {
            // 判断textField是否是数字
            
            if (![self isFloat:self.ageText]) {
                
                NSLog(@"不是数字");
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
                
                
            } else {
                NSLog(@"是数字");
                NSLog(@"保存年龄");
                [self.userXinXiNameDuiYingDic setValue:self.ageText forKey:@"年龄"];
                [self.jiBingJiuZhengTableView reloadData];
                
                // 进行BMI的计算
                [self simulateBMI];
                // 计算体脂率
                [self simulateTiZhiLv];
                
                // 提取年龄和BMI的权重
                for (int i = 0; i < self.scoreArray.count; i++) {
                    NSMutableDictionary *tempDic = self.scoreArray[i];
                    if ([[tempDic valueForKey:@"name"] isEqualToString:@"年龄"]) {
                        if (self.zgwAgeModel != nil) {
                            [tempDic setValue:self.zgwAgeModel.weight forKey:@"weight"];
                            float ageCount = [self.ageText floatValue];
                            if (ageCount >= 0 && ageCount <= 20) {
                                [tempDic setValue:self.zgwAgeModel.lessTwenty forKey:@"score"];
                            } else if (ageCount > 20 && ageCount <= 40) {
                                [tempDic setValue:self.zgwAgeModel.betweenTwentyToFourty forKey:@"score"];
                            } else if (ageCount > 40 && ageCount <= 60) {
                                [tempDic setValue:self.zgwAgeModel.betweenFourtyToSixty forKey:@"score"];
                            } else if (ageCount > 60 && ageCount <= 80) {
                                [tempDic setValue:self.zgwAgeModel.betweenSixtyToEighty forKey:@"score"];
                            }
                          //  [tempDic setValue:self.zgwAgeModel. forKey:@"score"];
                        } else  {
                            [tempDic setValue:@"0" forKey:@"weight"];
                            [tempDic setValue:@"0" forKey:@"score"];
                        }
                    }
                    
                    if ([[tempDic valueForKey:@"name"] isEqualToString:@"BMI"]) {
                        if (self.zgwBMIModel != nil) {
                            [tempDic setValue:self.zgwBMIModel.weight forKey:@"weight"];
                            float BMICount  = [[self.userXinXiNameDuiYingDic valueForKey:@"BMI"] floatValue];
                            if (BMICount < 0) {
                                // 未填
                                [tempDic setValue:@"0" forKey:@"score"];
                            } else if (BMICount >= 0 && BMICount <= 18.5) {
                                 [tempDic setValue:self.zgwBMIModel.lessEighteen forKey:@"score"];
                            } else if (BMICount > 18.5 && BMICount <= 24) {
                                 [tempDic setValue:self.zgwBMIModel.betweenEighteenToTwentyFour forKey:@"score"];
                            } else if (BMICount > 24 && BMICount <= 28) {
                                 [tempDic setValue:self.zgwBMIModel.betweenTwentyFourToTwentyEight forKey:@"score"];
                            } else if (BMICount > 28) {
                                 [tempDic setValue:self.zgwBMIModel.largerThanTwentyEight forKey:@"score"];
                            }
                        } else  {
                            [tempDic setValue:@"0" forKey:@"weight"];
                            [tempDic setValue:@"0" forKey:@"score"];
                        }
                    }
                }
                
                [self outputScoreArray];
                [self.jiBingJiuZhengTableView reloadData];
           
            }
        }

    } else {
        // 取消第一响应者
        [self.view endEditing:YES];
        if ([self.ageText containsString:@" "]) {
            NSLog(@"不能输入空格");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
        } else {
            // 判断textField是否是数字
            
            if (![self isFloat:self.ageText]) {
                
                NSLog(@"不是数字");
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
                
                
            } else {
                NSLog(@"是数字");
                NSLog(@"保存年龄");
                [self.userXinXiNameDuiYingDic setValue:self.ageText forKey:@"年龄"];
                [self.jiBingJiuZhengTableView reloadData];
                
                // 进行BMI的计算
                [self simulateBMI];
                // 计算体脂率
                [self simulateTiZhiLv];
                [self.jiBingJiuZhengTableView reloadData];
                // 计算纠正风险值
                [self simulateJiBingFengXianZhi];
            }
        }

    }
    
    
}


- (void)shenGaoFinish:(UIButton *)button
{
    NSLog(@"保存身高");
    if (self.isShiLiBaoGao == NO) {
        // 取消第一响应者
        [self.view endEditing:YES];
        if ([self.shenGaoText containsString:@" "]) {
            NSLog(@"不能输入空格");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
        } else {
            // 判断textField是否是数字
            
            if (![self isFloat:self.shenGaoText]) {
                
                NSLog(@"不是数字");
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
                
                
            } else {
                NSLog(@"是数字");
                NSLog(@"保存身高");
                [self.userXinXiNameDuiYingDic setValue:self.shenGaoText forKey:@"身高"];
                [self.jiBingJiuZhengTableView reloadData];
                
                // 进行BMI的计算
                [self simulateBMI];
                // 计算体脂率
                [self simulateTiZhiLv];
                
                // 提取BMI的权重
                for (int i = 0; i < self.scoreArray.count; i++) {
                    NSMutableDictionary *tempDic = self.scoreArray[i];
                    
                    if ([[tempDic valueForKey:@"name"] isEqualToString:@"BMI"]) {
                        if (self.zgwBMIModel != nil) {
                            [tempDic setValue:self.zgwBMIModel.weight forKey:@"weight"];
                            float BMICount  = [[self.userXinXiNameDuiYingDic valueForKey:@"BMI"] floatValue];
                            if (BMICount < 0) {
                                // 未填
                                [tempDic setValue:@"0" forKey:@"score"];
                            } else if (BMICount >= 0 && BMICount <= 18.5) {
                                [tempDic setValue:self.zgwBMIModel.lessEighteen forKey:@"score"];
                            } else if (BMICount > 18.5 && BMICount <= 24) {
                                [tempDic setValue:self.zgwBMIModel.betweenEighteenToTwentyFour forKey:@"score"];
                            } else if (BMICount > 24 && BMICount <= 28) {
                                [tempDic setValue:self.zgwBMIModel.betweenTwentyFourToTwentyEight forKey:@"score"];
                            } else if (BMICount > 28) {
                                [tempDic setValue:self.zgwBMIModel.largerThanTwentyEight forKey:@"score"];
                            }
                        } else  {
                            [tempDic setValue:@"0" forKey:@"weight"];
                            [tempDic setValue:@"0" forKey:@"score"];
                        }
                    }
                }
                [self outputScoreArray];
                
                [self.jiBingJiuZhengTableView reloadData];

            }
        }

    } else {
        // 取消第一响应者
        [self.view endEditing:YES];
        if ([self.shenGaoText containsString:@" "]) {
            NSLog(@"不能输入空格");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
        } else {
            // 判断textField是否是数字
            
            if (![self isFloat:self.shenGaoText]) {
                
                NSLog(@"不是数字");
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
                
                
            } else {
                NSLog(@"是数字");
                NSLog(@"保存身高");
                [self.userXinXiNameDuiYingDic setValue:self.shenGaoText forKey:@"身高"];
                [self.jiBingJiuZhengTableView reloadData];
                
                // 进行BMI的计算
                [self simulateBMI];
                // 计算体脂率
                [self simulateTiZhiLv];
                [self.jiBingJiuZhengTableView reloadData];
                // 计算纠正风险值
                [self simulateJiBingFengXianZhi];
            }
        }
      

    }
   
}

- (void)tiZhongFinish:(UIButton *)button
{
    NSLog(@"保存体重");
    if (self.isShiLiBaoGao == NO) {
        // 取消第一响应者
        [self.view endEditing:YES];
        if ([self.tiZhongText containsString:@" "]) {
            NSLog(@"不能输入空格");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
        } else {
            // 判断textField是否是数字
            
            if (![self isFloat:self.tiZhongText]) {
                
                NSLog(@"不是数字");
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
                
                
            } else {
                NSLog(@"是数字");
                NSLog(@"保存体重");
                [self.userXinXiNameDuiYingDic setValue:self.tiZhongText forKey:@"体重"];
                [self.jiBingJiuZhengTableView reloadData];
                
                // 进行BMI的计算
                [self simulateBMI];
                // 计算体脂率
                [self simulateTiZhiLv];
                
                // 提取BMI的权重
                for (int i = 0; i < self.scoreArray.count; i++) {
                    NSMutableDictionary *tempDic = self.scoreArray[i];
                    
                    if ([[tempDic valueForKey:@"name"] isEqualToString:@"BMI"]) {
                        if (self.zgwBMIModel != nil) {
                            [tempDic setValue:self.zgwBMIModel.weight forKey:@"weight"];
                            float BMICount  = [[self.userXinXiNameDuiYingDic valueForKey:@"BMI"] floatValue];
                            if (BMICount < 0) {
                                // 未填
                                [tempDic setValue:@"0" forKey:@"score"];
                            } else if (BMICount >= 0 && BMICount <= 18.5) {
                                [tempDic setValue:self.zgwBMIModel.lessEighteen forKey:@"score"];
                            } else if (BMICount > 18.5 && BMICount <= 24) {
                                [tempDic setValue:self.zgwBMIModel.betweenEighteenToTwentyFour forKey:@"score"];
                            } else if (BMICount > 24 && BMICount <= 28) {
                                [tempDic setValue:self.zgwBMIModel.betweenTwentyFourToTwentyEight forKey:@"score"];
                            } else if (BMICount > 28) {
                                [tempDic setValue:self.zgwBMIModel.largerThanTwentyEight forKey:@"score"];
                            }
                        } else  {
                            [tempDic setValue:@"0" forKey:@"weight"];
                            [tempDic setValue:@"0" forKey:@"score"];
                        }
                    }
                }
                [self outputScoreArray];
                
                
                [self.jiBingJiuZhengTableView reloadData];
  
            }
        }

    } else {
        // 取消第一响应者
        [self.view endEditing:YES];
        if ([self.tiZhongText containsString:@" "]) {
            NSLog(@"不能输入空格");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
        } else {
            // 判断textField是否是数字
            
            if (![self isFloat:self.tiZhongText]) {
                
                NSLog(@"不是数字");
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
                
                
            } else {
                NSLog(@"是数字");
                NSLog(@"保存年龄");
                [self.userXinXiNameDuiYingDic setValue:self.tiZhongText forKey:@"体重"];
                [self.jiBingJiuZhengTableView reloadData];
                
                // 进行BMI的计算
                [self simulateBMI];
                // 计算体脂率
                [self simulateTiZhiLv];
                [self.jiBingJiuZhengTableView reloadData];
                // 计算纠正风险值
                [self simulateJiBingFengXianZhi];
            }
        }
      

    }
   
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"textField = %@", textField.text);
    if ([textField.text containsString:@" "]) {
        NSLog(@"不能输入空格");
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
    } else {
        // 判断textField是否是数字
        
        if (![self isFloat:textField.text]) {
            
            NSLog(@"不是数字");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
            
            
        } else {
            NSLog(@"是数字");
            if (textField.tag == 300) {
                NSLog(@"保存年龄");
                [self.userXinXiNameDuiYingDic setValue:textField.text forKey:@"年龄"];
                [self.jiBingJiuZhengTableView reloadData];
            } else if (textField.tag == 301) {
                NSLog(@"保存身高");
                [self.userXinXiNameDuiYingDic setValue:textField.text forKey:@"身高"];
                [self.jiBingJiuZhengTableView reloadData];
            } else if (textField.tag == 302) {
                NSLog(@"保存体重");
                [self.userXinXiNameDuiYingDic setValue:textField.text forKey:@"体重"];
                [self.jiBingJiuZhengTableView reloadData];
            }
            
            // 进行BMI的计算
            [self simulateBMI];
            // 计算体脂率
            [self simulateTiZhiLv];
            [self.jiBingJiuZhengTableView reloadData];
            // 计算纠正风险值
            [self simulateJiBingFengXianZhi];
        }
    }
    
    [textField resignFirstResponder];
    return YES;
}

// 判断是否是整形
- (BOOL)isInt:(NSString *)string
{
    NSScanner *scan = [NSScanner scannerWithString:string];
    int val;
    return [scan scanInt:&val] && [scan isAtEnd];
}

// 判断是否为浮点型
- (BOOL)isFloat:(NSString *)string
{
    NSScanner *scan = [NSScanner scannerWithString:string];
    float val;
    return [scan scanFloat:&val] && [scan isAtEnd];
}

#pragma mark - BMI计算
- (void)simulateBMI
{
    if (self.isShiLiBaoGao == NO) {
        
        float tiZhong = [[self.userXinXiNameDuiYingDic valueForKey:@"体重"] floatValue];
        float shenGao = [[self.userXinXiNameDuiYingDic valueForKey:@"身高"] floatValue] / 100;
        if (tiZhong < 0 || shenGao < 0) {
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addTopGrayAlertNoImageWithContent:@"身高或者体重未填写，不能计算BMI" toView:self];
        } else {
            float BMI = tiZhong / (shenGao * shenGao);
            NSLog(@"shengao = %f", shenGao);
            NSLog(@"BMI = %f", BMI);
            NSString *BMIString = [NSString stringWithFormat:@"%f", BMI];
            [self.userXinXiNameDuiYingDic setValue:BMIString forKey:@"BMI"];
            //  NSLog(@"self.userXinXiDic = %@", self.userXinXiNameDuiYingDic);
        }
        
    } else {
        float tiZhong = [[self.userXinXiNameDuiYingDic valueForKey:@"体重"] floatValue];
        float shenGao = [[self.userXinXiNameDuiYingDic valueForKey:@"身高"] floatValue] / 100;
        float BMI = tiZhong / (shenGao * shenGao);
        NSLog(@"shengao = %f", shenGao);
        NSLog(@"BMI = %f", BMI);
        NSString *BMIString = [NSString stringWithFormat:@"%f", BMI];
        [self.userXinXiNameDuiYingDic setValue:BMIString forKey:@"BMI"];
        //  NSLog(@"self.userXinXiDic = %@", self.userXinXiNameDuiYingDic);
    }

}

#pragma mark - 计算体脂率
- (void)simulateTiZhiLv
{
    if (self.isShiLiBaoGao == NO) {
        // BMI
        float BMICount = [[self.userXinXiNameDuiYingDic valueForKey:@"BMI"] floatValue];
        // 性别
        NSString *genderString = [self.userXinXiNameDuiYingDic valueForKey:@"性别"];
        float genderCount = 0.0;
        if ([genderString isEqualToString:@"men"]) {
            genderCount = 1.0;
        } else if ([genderString isEqualToString:@"women"]) {
            genderCount = 0.0;
        }
        // 年龄
        float ageCount = [[self.userXinXiNameDuiYingDic valueForKey:@"年龄"] floatValue];
        float tiZhiCount = 1.2 * BMICount + 0.23 * ageCount - 5.4 - 10.8 * genderCount;
        NSLog(@"体脂率 = %f", tiZhiCount);
        [self.userXinXiNameDuiYingDic setValue:[NSString stringWithFormat:@"%f", tiZhiCount] forKey:@"体脂率"];
    } else {
        // BMI
        float BMICount = [[self.userXinXiNameDuiYingDic valueForKey:@"BMI"] floatValue];
        // 性别
        NSString *genderString = [self.userXinXiNameDuiYingDic valueForKey:@"性别"];
        float genderCount = 0.0;
        if ([genderString isEqualToString:@"men"]) {
            genderCount = 1.0;
        } else if ([genderString isEqualToString:@"women"]) {
            genderCount = 0.0;
        }
        // 年龄
        float ageCount = [[self.userXinXiNameDuiYingDic valueForKey:@"年龄"] floatValue];
        float tiZhiCount = 1.2 * BMICount + 0.23 * ageCount - 5.4 - 10.8 * genderCount;
        NSLog(@"体脂率 = %f", tiZhiCount);
        [self.userXinXiNameDuiYingDic setValue:[NSString stringWithFormat:@"%f", tiZhiCount] forKey:@"体脂率"];
    }
}


#pragma mark - 生活习惯点击回调
- (void)clickTag:(NSInteger)tag withShengHuoXiGuanName:(NSString *)name
{
    if (self.isShiLiBaoGao == NO) {
        // 提取那么对应的生活习惯model
        ZGWShengHuoXiGuanModel *model = [[ZGWShengHuoXiGuanModel alloc] init];
        for (ZGWShengHuoXiGuanModel *tempModel in self.zgwShengHuoXiGuanArray) {
            if ([tempModel.factor isEqualToString:name]) {
                model = tempModel;
            }
        }
        for (int i = 0; i < self.scoreArray.count; i++) {
            NSMutableDictionary *tempDic = self.scoreArray[i];
            if ([[tempDic valueForKey:@"name"] isEqualToString:name]) {
                [tempDic setValue:model.weight forKey:@"weight"];
                if (tag >=100 && tag < 200) {
                    // 说明点击的经常
                    NSLog(@"点击的第%ld个经常--生活习惯", tag - 100);
                    [tempDic setValue:model.often forKey:@"score"];
                    [self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic setValue:@"0" forKey:name];
                } else if (tag >=200 && tag < 300) {
                    // 说明点击的偶尔
                    NSLog(@"点击的第%ld个偶尔--生活习惯", tag - 200);
                    [tempDic setValue:model.once forKey:@"score"];
                    [self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic setValue:@"1" forKey:name];
                } else if (tag >=300 && tag < 400) {
                    // 说明点击的无
                    NSLog(@"点击的第%ld个无--生活习惯", tag - 300);
                    [tempDic setValue:model.without forKey:@"score"];
                    [self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic setValue:@"3" forKey:name];
                } else if (tag >= 400) {
                    // 说明点击的一般
                    NSLog(@"点击的第%ld个一般--生活习惯", tag - 400);
                    [tempDic setValue:model.common forKey:@"score"];
                    [self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic setValue:@"2" forKey:name];
                }
                
            }
        }
     
        NSLog(@"生活习惯的名字 = %@", name);
       
        [self outputScoreArray];
        [self.jiBingJiuZhengTableView reloadData];
    } else {
        if (tag >=100 && tag < 200) {
            // 说明点击的经常
            NSLog(@"点击的第%ld个经常--生活习惯", tag - 100);
            [self.shengHuoXiGuanNameDuiYingDic setValue:@"0" forKey:name];
        } else if (tag >=200 && tag < 300) {
            // 说明点击的偶尔
            NSLog(@"点击的第%ld个偶尔--生活习惯", tag - 200);
            [self.shengHuoXiGuanNameDuiYingDic setValue:@"1" forKey:name];
        } else if (tag >=300 && tag < 400) {
            // 说明点击的无
            NSLog(@"点击的第%ld个无--生活习惯", tag - 300);
            [self.shengHuoXiGuanNameDuiYingDic setValue:@"3" forKey:name];
        } else if (tag >= 400) {
            // 说明点击的一般
            NSLog(@"点击的第%ld个一般--生活习惯", tag - 400);
            [self.shengHuoXiGuanNameDuiYingDic setValue:@"2" forKey:name];
        }
        NSLog(@"生活习惯的名字 = %@", name);
        // 计算纠正风险值
        [self simulateJiBingFengXianZhi];
        // 重新提取展示在第一个cell上的数据
        [self tiQuXiangGuanZhiBingYinSuData];
        [self.jiBingJiuZhengTableView reloadData];
    }
   
}

#pragma mark - 疾病史的点击回调
- (void)clickTag:(NSInteger)tag withJiBingName:(NSString *)jiBingname
{
    if (self.isShiLiBaoGao == NO) {
        // 提取那么对应的生活习惯model
        ZGWDieaseHistoryModel *model = [[ZGWDieaseHistoryModel alloc] init];
        for (ZGWDieaseHistoryModel *tempModel in self.zgwJiBingShiArray) {
            if ([tempModel.factor isEqualToString:jiBingname]) {
                model = tempModel;
            }
        }
        for (int i = 0; i < self.scoreArray.count; i++) {
            NSMutableDictionary *tempDic = self.scoreArray[i];
            if ([[tempDic valueForKey:@"name"] isEqualToString:jiBingname]) {
                [tempDic setValue:model.weight forKey:@"weight"];
                if (tag >=100 && tag < 200) {
                    // 说明点击的严重
                    NSLog(@"点击的第%ld个严重--疾病史", tag - 100);
                    [tempDic setValue:model.serious forKey:@"score"];
                    [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:@"1" forKey:jiBingname];
                } else if (tag >=200 && tag < 300) {
                    // 说明点击的轻微
                    NSLog(@"点击的第%ld个轻微--疾病史", tag - 100);
                    [tempDic setValue:model.light forKey:@"score"];
                    [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:@"2" forKey:jiBingname];
                } else if (tag >=300) {
                    // 说明点击的无
                    NSLog(@"点击的第%ld个无--疾病史", tag - 100);
                     [tempDic setValue:model.without forKey:@"score"];
                    [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:@"3" forKey:jiBingname];
                }
            }
        }
        
        NSLog(@"疾病的名字 = %@", jiBingname);
        
        [self outputScoreArray];
        [self.jiBingJiuZhengTableView reloadData];

    } else {
        if (tag >=100 && tag < 200) {
            // 说明点击的严重
            NSLog(@"点击的第%ld个严重--疾病史", tag - 100);
            [self.jiBingShiNameDuiYingDic setValue:@"1" forKey:jiBingname];
        } else if (tag >=200 && tag < 300) {
            // 说明点击的轻微
            NSLog(@"点击的第%ld个轻微--疾病史", tag - 100);
            [self.jiBingShiNameDuiYingDic setValue:@"2" forKey:jiBingname];
        } else if (tag >=300) {
            // 说明点击的无
            NSLog(@"点击的第%ld个无--疾病史", tag - 100);
            [self.jiBingShiNameDuiYingDic setValue:@"3" forKey:jiBingname];
        }
        NSLog(@"疾病史的名字:%@", jiBingname);
        // 计算纠正风险值
        [self simulateJiBingFengXianZhi];
        // 重新提取展示在第一个cell上的数据
        [self tiQuXiangGuanZhiBingYinSuData];
        [self.jiBingJiuZhengTableView reloadData];
        
        
    }

    
}

#pragma mark - 字典转化为字符串
- (NSString *)dictionaryToJson:(NSDictionary *)dic
{
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

#pragma mark - 输出中文
- (NSString *)descriptionWithLocale:(id)locale
{
    
    NSMutableString *string = [[NSMutableString alloc] init];
    [string appendString:@"(\n"];
    for (id obj in locale) {
        [string appendFormat:@"%@\n", obj];
    }
    [string appendString:@")"];
    return string;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
